package service.impl;

import dao.UserDao;
import dao.impl.UserDaoImpl;
import domian.Result;
import domian.ResultStatus;
import domian.User;
import service.UpdateService;

public class UpdateServiceImpl implements UpdateService {

    /**
     * 修改昵称
     * @param user
     * @return
     */
    @Override
    public Result updateNick(User user) {
        ResultStatus rts = null;
        Result result = new Result();
        UserDao ud = new UserDaoImpl();

        if(user.getNickname() != ""){
            //昵称不为空则调用userdao修改昵称
            ud.updateUser(user);
            rts = ResultStatus.UPDATE_SUCCESS;
        }else {
            //昵称为空返回错误
            rts = ResultStatus.UPDATE_ERROR;
        }

        result.setCode(rts.getCode());
        result.setMsg(rts.getMsg());
        return result;
    }

    /**
     * 需改性别
     * @param user
     * @return
     */
    @Override
    public Result updateSex(User user) {
        ResultStatus rts = null;
        Result result = new Result();
        UserDao ud = new UserDaoImpl();

        //调用dao层更新到数据库
        ud.updateUser(user);
        rts = ResultStatus.UPDATE_SUCCESS;
        result.setCode(rts.getCode());
        result.setMsg(rts.getMsg());
        return result;
    }


    /**
     * 修改邮箱
     * @param user
     * @return
     */
    @Override
    public Result updateEmail(User user) {
        Result result = new Result();
        UserDao ud = new UserDaoImpl();

        //调用dao层更新到数据库
        ud.updateUser(user);
        ResultStatus rts = ResultStatus.UPDATE_SUCCESS;
        result.setCode(rts.getCode());
        result.setMsg(rts.getMsg());
        return result;
    }

    /**
     * 修改密码
     * @param user
     * @return
     */
    @Override
    public Result updatePassword(User user) {
        ResultStatus rts = null;
        Result result = new Result();
        UserDao ud = new UserDaoImpl();

        //调用dao层更新到数据库
        ud.updateUser(user);
        rts = ResultStatus.UPDATE_SUCCESS;
        result.setCode(rts.getCode());
        result.setMsg(rts.getMsg());
        return result;
    }


}
